<template>
    <div>
        数字： <h1>{{ sum }}</h1>
        <h1>{{ doubleAll }}</h1>
        <button @click='add'>+</button>
        <button @click='sub'>-</button>
        <News @send-joy="saveJoy" />
    </div>
</template>
<script setup lang='ts'>

import { ref } from 'vue';
import { userCountStore } from '@/store/count'
import { storeToRefs } from 'pinia'
import News from '@/components/News.vue';
import emitter from '@/utils/emitter'


//绑定一个事件
emitter.on('send-joy', (value) => {
    console.log('send-joy', value);
})

//方法
const countStore = userCountStore()
//变量解构
let { doubleAll, sum } = storeToRefs(countStore)

let count = ref(0)
function add() {
    // countStore.sum++;
    // countStore.$patch({
    //     sum:1000
    // })
    countStore.increment(1);
}
function saveJoy(value: string) {
    console.log(value);

}
function sub() {
    countStore.sum--;
}

</script>
<style scoped lang='scss'></style>@/utils/count
